

export default{
	methods:{
		async checkVersion(){
			// 当前版本
			const [system,local]=this.$store.state.appVersion.split('APP_')[1].split('_');
			let [l_whole,l_normal,l_hot]=local.split('.');
			l_whole=parseInt(l_whole)
			l_normal=parseInt(l_normal)
			l_hot=parseInt(l_hot)
			// 更新版本
			const {Version,Download,UpdatePack}=this.$store.state.updateInfo;
			let [u_whole,u_normal,u_hot]=Version.split('.');
			u_whole=parseInt(u_whole)
			u_normal=parseInt(u_normal)
			u_hot=parseInt(u_hot)
			console.log(u_normal,l_normal,u_normal>l_normal)
			if(u_normal>l_normal){// 正常更新
				uni.showModal({
					title:'',
					content:'发现新版本，点击确定更新',
					showCancel:false,
					confirmColor:this.$store.state.color.primary,
					success: (res) => {
						if(res.confirm){
							this.toPage(1,'/pages/update/index')
						}
					},
					complete: (e) => {
						let {confirm,cancel}=e;
						if(!confirm && !cancel){
							plus.runtime.quit();
						}
					}
				})
			}else{//热更新
				if(u_hot>l_hot){
					let url=Download+UpdatePack
					console.log(url)
					const downloadTask = uni.downloadFile({
						url,
						success: (res) => {
							console.log(res)
							if (res.statusCode === 200) {
								console.log('下载成功');
								plus.runtime.install(
									res.tempFilePath, {
										force: false
									},
									(res)=>{
										uni.showModal({
											title:'优房云系统',
											content:'发现新功能,是否重启应用?',
											confirmColor:this.$store.state.color.primary,
											showCancel:false,
											success: (modal) => {
												if(modal.confirm){
													plus.runtime.restart();
												}
											}
										})
									},
									(err)=> {
										this.utils.toast('安装失败,请联系管理员'+JSON.stringify(err));
									}
								);
							}
						},fail:(err)=>{
							console.log(err)
						}
					});
				}else{// 正常使用不更新
					this.getPower();
				}
			}
		}
	}
}